package com.yiqi.zhiyuan.feature.mine.view.adapter;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.suozhang.framework.utils.DensityUtil;
import com.yiqi.zhiyuan.R;

import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @ProjectName: ZhiYuan
 * @Description: java类作用描述
 * @Author: lijuwen
 * @CreateDate: 2019/4/16 10:23
 * @UpdateUser: 更新者
 * @UpdateDate: 2019/4/16 10:23
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class IntegralDialog extends Dialog {



    private Context context;

    private MyClickListenerInterface listenerInterface;
    private LayoutInflater layoutInflater;


    public IntegralDialog(Context context) {
        super(context, R.style.ActionImmediatelyDialogStyle);
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        init();
    }

    private void init() {
        View view = layoutInflater.inflate(R.layout.doalog_integral, null);
        ButterKnife.bind(this, view);
        setContentView(view);


        //获取当前Activity所在的窗体
        Window dialogWindow = getWindow();
        //设置Dialog从窗体底部弹出
        dialogWindow.setGravity(Gravity.CENTER);
        setCanceledOnTouchOutside(false);
    }

    @Override
    public void show() {
        super.show();
        /**
         * 设置宽度全屏，要设置在show的后面
         */
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.gravity = Gravity.CENTER;
        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;

        getWindow().getDecorView().setPadding(DensityUtil.dp2px(33), 0, DensityUtil.dp2px(33), 0);
        getWindow().setAttributes(layoutParams);


    }

    public void setListener(MyClickListenerInterface listener) {
        this.listenerInterface = listener;
    }



    @OnClick(R.id.btn_order_cancle)
    public void onViewClicked() {
        if (listenerInterface != null) {
            dismiss();
            listenerInterface.doConfirm();
        }else {
            dismiss();
        }
    }


    public interface MyClickListenerInterface {
        void doConfirm();
    }
}
